<template>
	<view>
		<Navbar></Navbar>
		<view class="u-m-20">
			<TeaList :list="teaList" :isBureau="true" @goTeaDetail="goTeaDetail"></TeaList>
		</view>
		<Loadmore :status="status"></Loadmore>
		<view style="height: 200rpx;"></view>
		<Bottom :isReturn="true" @confirm="confirm"></Bottom>
	</view>
</template>

<script>
	import Navbar from '@/components/Navbar.vue'
	import Bottom from '@/components/Bottom.vue'
	import TeaList from '@/components/TeaList.vue'
	import Loadmore from '@/components/Loadmore.vue'
	import reachBottom from '@/mixins/reachBottom.js'
	import { teaList } from '@/network/tea.js'
	import { formatDistance, pointTransform, presidentClass } from '@/utils/index.js'
	export default{
		mixins:[reachBottom],
		components:{
			Navbar,
			Bottom,
			TeaList,
			Loadmore
		},
		data(){
			return{
				teaList:[],
				status: 'loadmore'
			}
		},
		onLoad(){
			this.getTeaList()
		},
		methods:{
			getTeaList(){
				uni.showLoading({
					title: "加载中"
				})
				const params = {
					page: this.page,
					limit: this.pageSize,
					user_id: uni.getStorageSync("user_id"),
					is_top: 1
				}
				teaList(params).then(res=>{
					if(res.data.list.length > 0){
						res.data.list.map(item=>{
							switch(item.pay_type){
								case 1:
								    item.pay_name = '免费'
									break;
								case 2:
								    item.pay_name = `${item.price}`
									break;
								case 3:
								    item.pay_name = `${parseInt(item.price)}积分`
									break;
							}
							if(item.label){
								item.label = item.label.split("#").filter(item=>item !== null && item !== undefined && item)
							} 
							item.user.president_class = presidentClass(item.user.president_status)
							item.user.number = pointTransform(item.user.number)
							item.distance = formatDistance(item.distance)
							this.teaList.push(item)
						})
					}
					if(res.data.list.length < 10) this.status = 'nomore'
					uni.hideLoading()
				})
			},
			goTeaDetail(val) {
				uni.navigateTo({
					url: `/teaBureau/teaDetail/teaDetail?id=${val.id}`
				})
			},
			loadData() {
				if(this.status == 'nomore') return
				this.page++
				this.status = 'loading'
				this.getTeaList()
			},
		}
	}
</script>

<style>
</style>